package action_行为型.observer_pattern_观察者模式;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: hihi
 * @Date: 2020/07/09/16:42
 * @Description:
 */
public class Subject {

	private List<ObServer> obServers = new ArrayList<>();

	private int state;

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
		notifyAllObServer();
	}

	public void attachObServer(ObServer obServer) {
		obServers.add(obServer);
	}

	private void notifyAllObServer() {
		obServers.forEach(ObServer::update);
	}
}
